{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 定位"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#!/usr/bin/python\n",
    "# -*- coding: utf-8 -*-\n",
    "import json, urllib\n",
    "from urllib import urlencode\n",
    "  \n",
    "#----------------------------------\n",
    "# 经纬度地址解析调用示例代码 － 聚合数据\n",
    "# 在线接口文档：http://www.juhe.cn/docs/15\n",
    "#----------------------------------\n",
    "  \n",
    "def main():\n",
    "  \n",
    "    #配置您申请的APPKey\n",
    "    appkey = \"99b6fd576c6cb06dc071b44d30935237\"\n",
    "  \n",
    "    #1.经纬度地址解析\n",
    "    request1(appkey,\"GET\")\n",
    "  \n",
    "  \n",
    "  \n",
    "#经纬度地址解析\n",
    "def request1(appkey, m=\"GET\"):\n",
    "    url = \"http://apis.juhe.cn/geo/\"\n",
    "    params = {\n",
    "        \"lng\" : \"\", #经度 (如：119.9772857)\n",
    "        \"lat\" : \"\", #纬度 (如：27.327578)\n",
    "        \"key\" : appkey, #申请的APPKEY\n",
    "        \"type\" : \"\", #传递的坐标类型,1:GPS 2:百度经纬度 3：谷歌经纬度\n",
    "        \"dtype\" : \"\", #返回数据格式：json或xml,默认json\n",
    "  \n",
    "    }\n",
    "    params = urlencode(params)\n",
    "    if m ==\"GET\":\n",
    "        f = urllib.urlopen(\"%s?%s\" % (url, params))\n",
    "    else:\n",
    "        f = urllib.urlopen(url, params)\n",
    "  \n",
    "    content = f.read()\n",
    "    res = json.loads(content)\n",
    "    if res:\n",
    "        error_code = res[\"error_code\"]\n",
    "        if error_code == 0:\n",
    "            #成功请求\n",
    "            print res[\"result\"]\n",
    "        else:\n",
    "            print \"%s:%s\" % (res[\"error_code\"],res[\"reason\"])\n",
    "    else:\n",
    "        print \"request api error\"\n",
    "  \n",
    "  \n",
    "  \n",
    "if __name__ == '__main__':\n",
    "    main()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 逆地理编码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "import json\n",
    "import pandas as pd\n",
    "def regeocode(key,location='113.679287,23.632575',poitype=None,radius=None,extensions=\"all\",batch=False,roadlevel=None,sig=None,callback=None,homeorcorp=None) ->dict:\n",
    "    '''获得高德API逆地理编码'''\n",
    "    url = 'https://restapi.amap.com/v3/geocode/regeo?parameters'\n",
    "    params = {\n",
    "        'key':key_jw,\n",
    "        'location':location,\n",
    "        'poitype':poitype,\n",
    "        'radius':radius,\n",
    "        'extensions':extensions,\n",
    "        'batch':batch,\n",
    "        'roadlevel':roadlevel,\n",
    "        'sig':sig,\n",
    "        'output':'json',\n",
    "        'callback':callback,\n",
    "        'homeorcorp':homeorcorp\n",
    "    }\n",
    "    r = requests.get(url,params=params)\n",
    "    result = r.json()\n",
    "    return result\n",
    "革新路 = regeocode(key=key_jw,location=\"113.251893,23.092342\",extensions=\"all\")\n",
    "print(革新路)\n",
    "df_革新路 = pd.json_normalize(革新路)\n",
    "df_革新路"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
